layui.use('form', function () {
    var form = layui.form,
        $ = layui.jquery;

    //监听提交
    form.on('submit(savePerm)', function (data) {
        var auth = "";
        for (key in data.field) {
            auth += key + ","
        }
        auth = auth.substring(0, auth.length - 1);
        $.ajax({
            type: "post",
            url: "/role/editAuth",
            data: {"roleId": $("#id").val(), "auth": auth},
            success: function (data) {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }, error: function (xhr, status, error) {
                layer.msg("服务器异常")
            }
        });
        return false;
    });

    form.on('submit(save)', function (data) {
        var auth = "";
        delete data.field.name;
        for (key in data.field) {
            auth += key + ","
        }
        auth = auth.substring(0, auth.length - 1);
        $.ajax({
            type: "post",
            url: "/role/save",
            data: {"name": $("#name").val(), "auth": auth},
            success: function (data) {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }, error: function (xhr, status, error) {
                layer.msg("服务器异常")
            }
        });
        return false;
    });

    $(".cancel").click(function (data) {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
        return false;
    });
});